/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.action;

import static com.lineage.server.model.skill.L1SkillId.STATUS_BLUE_POTION;
import static com.lineage.server.model.skill.L1SkillId.STATUS_BLUE_POTION_OLDER;
import static com.lineage.server.packetserver.S_SkillIconGFX.BLUE_POTION;

import org.w3c.dom.Element;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.L1Item;
import com.lineage.server.packetserver.S_SkillIconGFX;

/**
 * Class <code>L1ItemReMpAction</code> 道具动作:回魔.
 * 
 * @author jrwz
 * @version 2012-6-23上午04:38:00
 * @see com.lineage.server.model.item.action
 * @since JDK1.7
 */
public final class L1ItemReMpAction extends L1ItemXmlAction {
    /** 类型. */
    private final String type;
    /** 回魔时间. */
    private final int reMpTime;

    /**
     * 道具动作:回魔.
     * 
     * @param element
     *            - XML 文档中的一个元素
     */
    public L1ItemReMpAction(final Element element) {
        super(element);
        this.type = element.getAttribute("类型");
        this.reMpTime = L1ItemXmlParser.getIntAttribute(element, "时间", 0);
    }

    @Override
    public L1Item execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        this.restorationMp(pc, this.reMpTime);
        if (this.type.equalsIgnoreCase("一般")) {
            // 给予蓝水时间 (秒)
            pc.setSkillEffect(STATUS_BLUE_POTION, this.reMpTime * 1000);
        } else if (this.type.equalsIgnoreCase("古老")) {
            pc.setSkillEffect(STATUS_BLUE_POTION_OLDER, this.reMpTime * 1000);
        }
        return null;
    }

    /**
     * 回复魔力.
     * 
     * @param pc
     *            - 对象
     * @param time
     *            - 持续时间
     */
    private void restorationMp(final L1PcInstance pc, final int time) {
        pc.delAbsoluteBarrier(); // 删除绝对屏障效果
        pc.delRepeatSkillEffect(STATUS_BLUE_POTION); // 删除重复的蓝水效果
        pc.delRepeatSkillEffect(STATUS_BLUE_POTION_OLDER); // 删除重复的古老的蓝水效果
        pc.sendPackets(new S_SkillIconGFX(BLUE_POTION, time)); // 发送状态图示
        PacketCreate.get().sendSinglePackets(pc, "你感觉到魔力恢复速度加快");
    }
}
